import { BaseItem } from "./BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EColor } from "../../../../Message/Public/EColor";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ModelType } from "../../scene/modle/data/ModelType";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
//class GoodsItem
    
    export  class GoodsItem extends BaseItem
    {
        constructor()
        {
            super();
            this._spStrengthEffect = new Object /* flash.display.Sprite */();
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            return;
        }

        protected onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            if (this._swfStrength) 
            {
                this._swfStrength.play();
            }
            return;
        }

        protected onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            if (this._swfStrength) 
            {
                this._swfStrength.stop();
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            this.clearEquipmentEffect();
            super.data = arg1;
            return;
        }

        public /* override */ set itemData(arg1: ItemData)
        {
            super.itemData = arg1;
            this.clearEquipmentEffect();
            this.addEquipmentEffect();
            return;
        }

        /* internal  */addEquipmentEffect(): void
        {
            if (itemData && (itemData.category == ECategory._ECategoryEquip || itemData.category == ECategory._ECategoryMount || itemData.category == ECategory._ECategoryPetEquip)) 
            {
                var loc1=itemData.color;
                switch (loc1) 
                {
                    case EColor._EColorGreen:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.GreenFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect1.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                    case EColor._EColorBlue:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.BlueFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect2.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                    case EColor._EColorPurple:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.PurpleFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect3.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                    case EColor._EColorOrange:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.OrangeFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect4.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                    case EColor._EColorRed:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.OrangeFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo && (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60)) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect5.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                    case EColor._EColorRedGold:
                    {
                        this._bmpOver = GlobalClass.getBitmap(ImagesConst.RedFrame);
                        this.addChild(this._bmpOver);
                        if (itemData.itemExInfo && (itemData.itemExInfo.strengthen >= 6 || itemData.itemExInfo.m_adv_lv >= 60)) 
                        {
                            this.addStrengthSWFPlayer();
                            this._swfStrength.load("itemEffect6.swf", ModelType.Skill, null);
                        }
                        else 
                        {
                            this.disposeStrengthSWFPlayer();
                        }
                        break;
                    }
                }
                this.resetEffectPosition();
            }
            return;
        }

        public setOverPosition(arg1: number=1, arg2: number=1, arg3: number=36, arg4: number=36): void
        {
            this._bmpOverX = arg1;
            this._bmpOverY = arg2;
            this._bmpOverWidth = arg3;
            this._bmpOverHeight = arg4;
            this.resetEffectPosition();
            return;
        }

        /* internal  */resetEffectPosition(): void
        {
            if (this._swfStrength) 
            {
                this._swfStrength.move(17 + this._bmpOverX, 18 + this._bmpOverY);
            }
            if (this._bmpOver) 
            {
                this._bmpOver.x = this._bmpOverX;
                this._bmpOver.y = this._bmpOverY;
                this._bmpOver.width = this._bmpOverWidth;
                this._bmpOver.height = this._bmpOverHeight;
            }
            return;
        }

        /* internal  */clearEquipmentEffect(): void
        {
            if (this._bmpOver && this._bmpOver.parent) 
            {
                this._bmpOver.parent.removeChild(this._bmpOver);
            }
            this.disposeStrengthSWFPlayer();
            return;
        }

        /* internal  */addStrengthSWFPlayer(): void
        {
            if (!this._swfStrength) 
            {
                this._swfStrength = ObjectPool.getObject(SWFPlayer);
                this._swfStrength.move(17 + this._bmpOverX, 18 + this._bmpOverY);
                this.addChild(this._swfStrength);
            }
            return;
        }

        /* internal  */disposeStrengthSWFPlayer(): void
        {
            if (this._swfStrength) 
            {
                this._swfStrength.dispose();
                ObjectPool.disposeObject(this._swfStrength, SWFPlayer);
                this._swfStrength = null;
            }
            return;
        }

        /* internal */ /* var */_bmpOver: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bmpOverX: number=1;

        /* internal */ /* var */_bmpOverY: number=1;

        /* internal */ /* var */_bmpOverWidth: number=36;

        /* internal */ /* var */_bmpOverHeight: number=36;

        /* internal */ /* var */_spStrengthEffect: Object /* flash.display.Sprite */;

        /* internal */ /* var */_swfStrength: SWFPlayer;
    }
